FROM python:3.7-slim

WORKDIR /app/AzurLane

# System dependencies
RUN echo "\
Types: deb deb-src\n\
URIs: http://mirrors.tencent.com/debian/\n\
Suites: trixie trixie-updates trixie-backports\n\
Components: main contrib non-free non-free-firmware\n\
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg\n\n\
Types: deb deb-src\n\
URIs: http://mirrors.tencent.com/debian-security\n\
Suites: trixie-security\n\
Components: main contrib non-free non-free-firmware\n\
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg" \
> /etc/apt/sources.list.d/debian.sources \
    && apt-get update && apt-get install -y --no-install-recommends \
       git adb libgomp1 openssh-client ca-certificates curl \
    && git config --global --add safe.directory '*' \
    && ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
    && echo 'Asia/Shanghai' > /etc/timezone \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/* \
    && cd .. && git clone https://github.com/LmeSzinc/AzurLaneAutoScript.git AzurLane && cd AzurLane/deploy/docker \
# Install Miniconda (Miniconda3-py313_25.9.1-3) \
    && curl -o /tmp/miniconda.sh https://repo.anaconda.com/miniconda/Miniconda3-py313_25.9.1-3-Linux-x86_64.sh \
    && bash /tmp/miniconda.sh -b -p /opt/conda \
    && rm /tmp/miniconda.sh \
# Add the conda-forge channel \
# Remove only defaults channel \
# Set the priority as strict (make sure it only pull from conda-forge channel) \
# Add the conda-forge channel \
    && export PATH=/opt/conda/bin:$PATH \
    && conda config --system --remove channels defaults \
    && conda config --system --add channels conda-forge \
    && conda config --system --set channel_priority strict \
    && conda install -y mamba \
# Install PyAV according to requirements.txt \
    && AV_VERSION=$(grep -E '^av==' requirements.txt | cut -d '=' -f 3) \
    && echo "Installing av == $AV_VERSION" \
    && mamba install -y "python=3.7" "av==$AV_VERSION" \
    && conda clean --all --yes \
# Install other pip dependencies (skip av) \
    && pip config set global.index-url https://mirrors.tencent.com/pypi/simple/ \
    && grep -v '^av==' requirements.txt > /tmp/requirements_no_av.txt \
    && pip install --no-cache-dir -r /tmp/requirements_no_av.txt \
    && rm /tmp/requirements_no_av.txt \
    && echo "[ENV_CHECK_START]========================================" \
    && echo "Final Environment Verification Checks (After all installations):" \
    \
    && echo "1. Python Version Check (should be 3.7.x):" \
    && python --version \
    \
    && echo "2. Pip Path Check (should be /opt/conda/bin/pip):" \
    && which pip \
    \
    && echo "3. Complete Package List (Conda and Pip):" \
    && conda list \
    && echo "[ENV_CHECK_END]=========================================="

ENV PATH=/opt/conda/bin:$PATH

CMD ["python", "gui.py"]
#CMD ["python"]

